package com.tx.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tx.user.dao.UserDao;
import com.tx.user.pojo.User;
import com.tx.user.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao userDao;

	public User login(User user) {
		User u = userDao.selectByName(user);
		if(u != null) {
			if(u.getUsername().equals(user.getUsername()) && u.getPassword().equals(user.getPassword())) {
				return u;
			}
		}
		return null;
	}

	public List<User> selectAll() {
		return userDao.selectAll();
	}

	public boolean updateTime(User u) {
		int n = userDao.updateTime(u);
		return n > 0;
	}

	public boolean deleteUserById(User u) {
		int n = userDao.deleteUserById(u);
		return n > 0;
	}

	public boolean addUser(User u) {
		int n = userDao.addUser(u);
		return n > 0;
	}

	public boolean updateUser(User u) {
		int n = userDao.updateUser(u);
		return n > 0;
	}

	public User selectUserById(User u) {
		User user = userDao.selectById(u);
		return user;
	}

	public List<User> selectUserWithUsername(User user) {
		List<User> list = userDao.selectUserWithUsername(user);
		return list;
	}
	
}
